<?php

/*
// @author : lael
// blog : http://hi.baidu.com/lael80
// http://www.gzyd.net
// all right reserved.
*/

namespace ydsdk\controllers\admin;

class shuttle extends \ydsdk\core\admin {
	public function __construct(){
		parent::__construct();
		if($_SESSION['admin']['type'] != 2)show_message('没有访问权限', siteurl('con=admin/index'));
	}

	public function index(){
		$where = '{1}.sid='.$_SESSION['admin']['admin_id'];
		if($_GET['keywords'])$where .= " and ({0}.iccode='".$_GET['keywords']."' or {0}.device_id='".$_GET['keywords']."' or {1}.name='".$_GET['keywords']."')";
		$list = $this->db->get_page(array('deerxi_shuttle', 'deerxi_student'), '{0}.*,{1}.name', 'left join {1} on {0}.sid={1}.id where '.$where.' order by {0}.id desc', false, $_GET['page'], $_GET['pagesize']?:20);
		$this->smarty->assign('list', $list);
		$this->smarty->display('shuttle/index.html');
	}
	
	public function delete(){
		if(!empty($_POST['ids'])){
			//$this->db->delete('deerxi_shuttle', 'id in ('.$_POST['ids'].')');	
			$this->db->delete('delete a from ##deerxi_shuttle as a left join ##deerxi_student as b on a.sid=b.id where a.id in ('.$_POST['ids'].') and b.sid='.$_SESSION['admin']['admin_id']);
		}
		exitjson(1);	
	}
}
